/*
 * @Descripttion: 读取xlsx内容
 * @version: 1.0
 * @LastEditors: HR
 * @LastEditTime: 2021年7月10日10:16:16
 */

const importfile = (obj, callback) => {
    let f = obj;
    let reader = new FileReader();
    let filedata = [];
    reader.onload = async function () {
      let rABS = false; //是否将文件读取为二进制字符串
      let wb;
      let XLSX = require("xlsx");
      let bytes = new Uint8Array(reader.result);
      let length = bytes.byteLength;
      let binary = "";
      for (let i = 0; i < length; i++) {
        binary += String.fromCharCode(bytes[i]);
      }
      console.log(binary);
      //此处引入，用于解析excel
      if (rABS) {
        wb = XLSX.read(btoa(binary), {
          //手动转化
          type: "base64",
        });
      } else {
        wb = XLSX.read(binary, {
          type: "binary",
        });
      }
      filedata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
      callback(filedata);
    };
    reader.readAsArrayBuffer(f);
  };
  export  {importfile}